<template>
	<view class="container">
		<u-navbar leftText="中奖名单" @leftClick="goBack" leftIconColor="#1D2129" bgColor="transparent">
		</u-navbar>
		<view class="content">
			<view class="sweepstakes_name ex">
				活动名称: {{ activityName }}
			</view>
			<scroll-view @scrolltolower="scrolltolower" scroll-y scroll-with-animation class="content_scroll_view">
				<view class="item_list" v-for="(item, index) in dataList" :key="index">
					<view class="item_top">
						<img v-if="item.avatar" class="item_avatar" :src="item.avatar" />
						<img v-else class="item_avatar"
							src="https://weilebo-img.oss-cn-hangzhou.aliyuncs.com/vlebo/defaultavatar.png" />
						<view class="item_title ex">{{ item.nickname }}</view>
					</view>
					<view class="item_bottom">
						<view class="item">
							<view class="item_condition">
								<view class="label">中奖内容：</view>
								<view class="item_value ex">{{ item.prizeName }}</view>
							</view>
						</view>
						<template v-if="checkType == 1">
							<view class="item">
								<view class="item_condition flex_width_45">
									<view class="label">核销状态：</view>
									<view class="item_value ex" :class="item.status == 1 ? '' : 'no_hx'">
										{{ item.status == 1 ? '已核销': '未核销' }}
									</view>
								</view>
								<view class="item_condition">
									<view class="label">核销码：</view>
									<view class="item_value ex">{{ item.checkCode }}</view>
									<view class="item_btn" v-if="item.status !== 1"
										@click="writeOff(item.nickname,item.checkCode)">
										<img src="@/static/image/edit.png" />
										<text>核销</text>
									</view>
								</view>
							</view>
							<view class="item">
								<view class="item_condition flex_width_65">
									<view class="label">核销时间：</view>
									<view class="item_value ex">{{ item.checkTime }}</view>
								</view>
								<view class="item_condition">
									<view class="label">核销人：</view>
									<view class="item_value ex">{{ item.operatorName }}</view>
								</view>
							</view>
						</template>
						<template v-if="checkType == 0">
							<view class="item">
								<view class="item_condition flex_width_45">
									<view class="label">用户姓名：</view>
									<view class="item_value ex">{{ item.username }}</view>
								</view>
								<view class="item_condition">
									<view class="label">手机号码：</view>
									<view class="item_value ex">{{ item.mobile }}</view>
								</view>
							</view>
							<view class="item">
								<view class="item_condition">
									<view class="label">地址：</view>
									<view class="item_value">{{ item.address }}</view>
								</view>
							</view>
						</template>
					</view>
				</view>
				<div class="listSpace" v-if="dataList.length <= 0">
					<list-space></list-space>
				</div>
				<view class="cj_space"></view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [],
				activityName: '',
				total: 0,
				checkType: 0,
				params: {
					id: undefined,
					page: 1,
					pageSize: 10,
				}
			}
		},
		onLoad() {
			this.params.id = this.$route.query.id
			this.checkType = this.$route.query.checkType
			this.activityName = this.$route.query.name
			// 获取流量情况
			this.getList()
		},
		onPullDownRefresh() {
			this.params.page = 1
			this.dataList = []
			this.getList()
		},
		methods: {
			goBack() {
				uni.navigateBack();
			},
			writeOff(name, checkCode) {
				uni.showModal({
					title: '提示',
					content: `是否核销【${name}】的奖品?`,
					success: async (res) => {
						if (res.confirm) {
							const {
								data
							} = await this.$request(this.$Api.checkWinPrize, {
								checkCode: checkCode
							}, "POST")
							if (data.code != 200) return
							uni.showToast({
								title: '核销成功!',
								icon: 'none'
							})
							this.params.page = 1
							this.dataList = []
							this.getList()
						}
					}
				})
			},
			// 滚动到底部加载更多
			scrolltolower(e) {
				if (this.dataList.length < this.total) {
					this.params.page++
					this.getList()
				} else {
					uni.showToast({
						title: '已到底',
						icon: 'none'
					})
				}
			},
			async getList() {
				const {
					data
				} = await this.$request(this.$Api.drawWinPrizeCustomer + "/" + this.params.id, this.params, "get")
				data.data.forEach((item) => {
					const addressTotal = item.address.split('/');
					item.username = addressTotal[0];
					item.mobile = addressTotal[1];
					item.address = addressTotal.length === 3 ? addressTotal[2] : '-';
				});
				this.dataList = this.dataList.concat(data.data)
				this.total = data.total
				uni.stopPullDownRefresh()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		position: relative;
		height: 100vh;
		overflow-y: hidden;
		background: url('@/static/image/my_set_bg.png')#FAFBFF no-repeat center center;
		background-size: cover;

		::v-deep .u-navbar__content__left__text {
			font-weight: 500;
			font-size: 32rpx;
		}

		.content {
			display: flex;
			flex-direction: column;
			margin-top: 96rpx;
			height: calc(100vh - 96rpx);
			box-sizing: border-box;

			.sweepstakes_name {
				font-weight: 500;
				font-size: 28rpx;
				color: #464C5B;
				height: 40rpx;
				line-height: 40rpx;
				padding: 0 32rpx;
				margin-bottom: 24rpx;
			}

			.content_scroll_view {
				height: calc(100vh - 160rpx);

				.item_list {
					background: #fff;
					border-radius: 14rpx;
					margin: 0 32rpx 24rpx 32rpx;

					.item_top {
						display: flex;
						align-items: center;
						padding: 16rpx 24rpx;
						border-bottom: 2rpx solid #D7DDE4;

						.item_avatar {
							width: 72rpx;
							height: 72rpx;
							border-radius: 50%;
						}

						.item_title {
							font-weight: 500;
							font-size: 28rpx;
							color: #464C5B;
							margin-left: 16rpx;
						}
					}

					.item_bottom {
						box-sizing: border-box;
						padding-bottom: 24rpx;

						.item {
							display: flex;
							align-items: center;
							height: 40rpx;
							margin-top: 22rpx;
							padding: 0 24rpx;
							box-sizing: border-box;
							font-size: 24rpx;
							color: #8C8C8C;

							.item_condition {
								flex: 1;
								display: flex;

								.label {
									white-space: nowrap;
								}

								.item_value {
									color: #464C5B;
								}

								.no_hx {
									color: #295EFF;
								}

								.item_btn {
									display: flex;
									align-items: center;
									font-weight: 400;
									font-size: 24rpx;
									color: #295EFF;
									margin-left: 18rpx;

									img {
										width: 24rpx;
										height: 24rpx;
										margin-right: 8rpx;
									}
								}
							}

							.flex_width_45 {
								flex: none;
								width: 45%;
							}

							.flex_width_65 {
								flex: none;
								width: 65%;
							}
						}
					}
				}

			}
		}

		.cj_space {
			width: 100%;
			height: 1rpx;
		}
	}
</style>